package com.jiayang.business.Infraredthresholdpage;

import com.jiayang.base.sensor.StaSensorMapper;
import com.jiayang.base.sensor.domain.entity.StaSensor;
import com.jiayang.business.equipmentinfopage.domain.dto.ThresholdDTO;
import com.jiayang.common.domain.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

/**
 * @ Author     ：OuyangChenglong
 * @ Date       ：Created in 10:11 2021/9/8
 * @ Description：红外阈值设备页
 * @ Modified By：
 * @Version: $
 */
@Service
public class InfraredThresholdService {

    @Autowired
    private StaSensorMapper sensorDao;

    @Autowired
    private InfraredThresholdDao infraredThresholdDao;

    @Transactional
    public ResponseDTO addThreshold(ThresholdDTO thresholdDTO) {
        // 根据传感器获取公司id
        StaSensor StaSensor = sensorDao.selectById(thresholdDTO.getSensorId());
        String companyId = StaSensor.getCompanyId();
        // TODO 直接添加对象存在BUG
        //ThresholdEntity thresholdEntity = JYangBeanUtil.copy(thresholdDTO, ThresholdEntity.class);
        // 新增测点阈值
        String uuid = UUID.randomUUID().toString();
        //thresholdEntity.setId(uuid);
        //thresholdEntity.setCompanyId(companyId);
        try {
            infraredThresholdDao.addThreshold(uuid,companyId,thresholdDTO.getSensorId(),thresholdDTO.getErrorName(),thresholdDTO.getMax(),thresholdDTO.getMin(),thresholdDTO.getPointName(),thresholdDTO.getXLocation(),thresholdDTO.getYLocation());
            return ResponseDTO.succMsg("测点添加成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseDTO.succMsg("测点添加失败");
    }
}
